package com.rental.web.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rental.common.exception.ProjectException;
import com.rental.common.result.AjaxResult;
import com.rental.common.result.ResultCodeEnum;
import com.rental.common.util.AjaxResultHandler;
import com.rental.houses.client.RequiredHouseFegin;
import com.rental.model.entity.house.RequiredHouse;
import com.rental.model.entity.user.UserInfo;
import com.rental.model.form.house.RequiredHouseForm;
import com.rental.model.form.house.RequiredHousePage;
import com.rental.model.form.house.RequiredReportForm;
import com.rental.model.vo.house.RequiredHouseVo;
import com.rental.quickenPoint.client.UserAccountClient;
import com.rental.user.client.UserInfoFeignClient;
import com.rental.web.service.RequiredHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RequiredHouseServiceImpl implements RequiredHouseService {


    @Autowired
    private RequiredHouseFegin requiredHouseFegin;

    @Autowired
    private UserAccountClient userAccountClient;


    @Override
    public Boolean addRequiredHouse(RequiredHouseForm requiredHouseForm) {
        // 增加加速值
        if (!AjaxResultHandler.handle(userAccountClient.sendAccelerateValueByAddInfo(requiredHouseForm.getUid())))
            throw new ProjectException(ResultCodeEnum.QUICKEN_ADD_ERROR);
        requiredHouseFegin.addRequiredHouse(requiredHouseForm);
        return true;
    }


    @Autowired
    private UserInfoFeignClient userInfoFeignClient;

    @Override
    public RequiredHouseVo getRequiredHouseDetail(Long id) {
        //        并且将用户的头像封装到返回对象中
        RequiredHouseVo requiredHouseVo = requiredHouseFegin.getRequiredHouseDetail(id).getData();
        return requiredHouseVo;
    }

    @Override
    public Boolean deleteRequiredHouse(Long id) {
        return requiredHouseFegin.deleteRequiredHouse(id).getData();
    }


    @Override
    public RequiredHouseVo getRequiredHouseById(Long id,Long userId) {
        return requiredHouseFegin.getRequiredHouseById(id, userId).getData();
    }

    @Override
    public Boolean reportRequiredHouse(RequiredReportForm requiredReportForm) {

        return requiredHouseFegin.reportRequiredHouse(requiredReportForm).getData();
    }

    @Override
    public Boolean collect(Long rid, Long uid) {
        return requiredHouseFegin.collect(rid, uid).getData();
    }

    @Override
    public Boolean cancelCollect(Long rid, Long uid) {
        return requiredHouseFegin.cancelCollect(rid, uid).getData();
    }

    @Override
    public Page<RequiredHousePage> getRequiredHouseList(Integer current, Integer size, RequiredHouseForm requiredHouseForm) {
        return requiredHouseFegin.getRequiredHouseList(current, size, requiredHouseForm).getData();
    }




    @Override
    public Boolean updateRequiredHouse(RequiredHouseForm requiredHouseForm) {
        return requiredHouseFegin.updateRequiredHouse(requiredHouseForm).getData();
    }


}
